package com.rural.bus.config;

import android.content.Context;
import android.content.SharedPreferences;

import com.rural.bus.MyApplication;

/**
 * 全局sharedpreference管理类，单例模式，调用instance()获得单例对象
 * @author lingwei.wang@bitbao.net
 *
 */
public class MyPreferenceManager {
	/** sharedpreference 前缀 */
	public final static String PREFERENCE_PRE = "com.rural.bus";
	
	/** sharedpreference 对象 */
	public SharedPreferences mAppPreference = MyApplication.instance().getSharedPreferences(PREFERENCE_PRE, Context.MODE_PRIVATE);
	
	private static MyPreferenceManager sPreference;
	
	public static MyPreferenceManager instance(){
		if(sPreference == null){
			sPreference = new MyPreferenceManager();
		}
		
		return sPreference;
	}
	
	public void clearPreferences(){
		mAppPreference.edit().clear().commit();
	}
	
	public void putSharedInfoOfString(String key, String value) {
		mAppPreference.edit().putString(key, value).commit();
	}
	
	public String getSharedInfoByKey(String key, String defaultValue) {
		return mAppPreference.getString(key, defaultValue);
	}
	
	public void putSharedInfoOfInt(String key, int value) {
		mAppPreference.edit().putInt(key, value).commit();
	}
	
	public int getSharedInfoByKey(String key, int defaultValue) {
		return mAppPreference.getInt(key, defaultValue);
	}
	
	public void putSharedInfoOfLong(String key, int value) {
		mAppPreference.edit().putInt(key, value).commit();
	}
	
	public long getSharedInfoByKey(String key,Long defaultValue) {
		return mAppPreference.getLong(key, defaultValue);
		
	}
	
	public void putSharedInfoOfBoolean(String key, boolean value) {
		mAppPreference.edit().putBoolean(key, value).commit();
	}
	
	public boolean getSharedInfoByKey(String key,boolean defaultValue) {
		return mAppPreference.getBoolean(key, defaultValue);
	}
	
}
